home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
mousport.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
10KB
|
254 lines
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
/* *********************************************************************** */
/* mouse test, for right game port on the Amiga.
Notes: The right port is used for this test because the input.device
task is busy continuously with the lefthand port, feeding input events
to intuition or console devices. If Intuition is not activated
(applications which take over the whole machine may decide not to
activate Intuition), and if no console.device is activated either,
the input.device will never activate... allowing the application
free reign to use either the left OR the right hand joystick/mouse
port. If either intuition or the console device are activated,
the lefthand port will yield, at best, every alternate input
event to an external application such as this test program.
This will undoubtedly mess up either of the two applications
and should therefore be avoided. It was ok to use the right
port in this case, since the system has no particular interest
in monitoring it.
*********************************************************************** */
/* #include "intuall.h" */
#include <exec/types.h>
#include <graphics/gfx.h>
#include <devices/gameport.h>
#include <devices/inputevent.h>
LONG GfxBase=0;
#define XMOVE 10
#define YMOVE 10
#define MAX(m,n) (m > n ? m : n)
struct GamePortTrigger mousetrigger = {
GPTF_UPKEYS + GPTF_DOWNKEYS,
1800,
XMOVE,
YMOVE };
/* trigger on all mouse key transitions, and every 30 seconds, and
for any 10 in an x or y direction */
struct InputEvent *game_data; /* pointer into the returned data area
* where input event has been sent */
SHORT error;
struct IOStdReq *game_io_msg;
BYTE gamebuffer[sizeof( struct InputEvent )];
BYTE *gamedata;
SHORT testval;
struct Port *game_msg_port;
SHORT movesize;
extern struct Port *CreatePort();
extern struct IOStdReq *CreateStdIO();
SHORT codeval, timeouts;
#define IF_NOT_IDLE_TWO_MINUTES while(timeouts < 4)
main()
{
GfxBase = OpenLibrary("graphics.library", 0);
if (GfxBase == NULL)
{
printf("Unable to open graphics library\n");
exit(1000);
}
printf("Mouseport Demo\n");
printf("\nMove Mouse from Left Port to Right Port\n");
printf("\nThen move the mouse and click its buttons");
timeouts = 0;
gamedata = &gamebuffer[0];
/* point to first location in game buffer */
game_msg_port = CreatePort(0,0);
/* provide a port for the IO response */
if(game_msg_port == 0)
{
printf("\nError While Performing CreatePort");
exit(-1);
}
game_io_msg = CreateStdIO(game_msg_port);
/* make an io request block for communicating with
the keyboard */
if(game_io_msg == 0)
{
printf("\nError While Performing CreateStdIO");
DeletePort(game_msg_port);
exit(-2);
}
error = OpenDevice("gameport.device",1,game_io_msg,0);
/* open the device for access, unit 1 is right port */
if(error != 0)
{
printf("\nError while opening the device, exiting");
DeleteStdIO(game_io_msg);
DeletePort(game_msg_port);
exit(-3);
}
game_io_msg->io_Length = sizeof(struct InputEvent);
/* read one event each time we go back to the gameport */
game_io_msg->io_Data = gamebuffer;
/* show where to put the data when read */
game_data = (struct InputEvent *)gamebuffer;
/* test the mouse in this loop */
set_controller_type(GPCT_MOUSE);
game_io_msg->io_Command = GPD_SETTRIGGER;
/* specify the trigger conditions */
game_io_msg->io_Data = &mousetrigger;
/* show where to find the trigger condition info */
/* this command doesn't wait... returns immediately */
SendIO(game_io_msg);
WaitPort(game_msg_port);
GetMsg(game_msg_port);
printf("\nI will report:");
printf("\n Mouse X or Y moves if either is over 10 counts");
printf("\n Button presses (along with mouse moves if any)");
printf("\n Or every 30 seconds (along with mouse moves if any)");
printf("\n if neither move or click happens\n");
printf("\nIf no activity for 2 minutes, the program exits\n");
game_io_msg->io_Command = GPD_READEVENT;
/* from now on, just read input events */
game_io_msg->io_Data = gamebuffer;
/* into the input buffer, one at a time. */
/* read-event waits for the preset conditions */
IF_NOT_IDLE_TWO_MINUTES
{
game_io_msg->io_Length = sizeof(struct InputEvent);
/* read one event each time we go back to the gameport */
printf("\n Waiting For Mouse Report\n");
SendIO(game_io_msg);
WaitPort(game_msg_port);
/* this is NOT a busy wait... it is a task-sleep */
GetMsg(game_msg_port);
codeval = game_data->ie_Code;
switch(codeval)
{
case IECODE_LBUTTON:
printf("\nMouse Left Button Pressed");
maybe_mouse_moved();
break;
case IECODE_RBUTTON:
printf("\nMouse Right Button Pressed");
maybe_mouse_moved();
break;
case (IECODE_LBUTTON + IECODE_UP_PREFIX):
printf("\nMouse Left Button Released");
maybe_mouse_moved();
break;
case (IECODE_RBUTTON + IECODE_UP_PREFIX):
printf("\nMouse Right Button Released");
maybe_mouse_moved();
break;
case IECODE_NOBUTTON:
timeouts++; /* after 2 minutes, dump program
* if user loses interest
*/
movesize = maybe_mouse_moved();
if(movesize == 0)
printf("\n30 seconds passed, no trigger events");
else if(movesize < XMOVE && movesize < YMOVE )
{
printf("\n(Even though less than trigger count,");
printf("\n reporting mouse move at the selected");
printf("\n timing interval for user info)");
}
break;
default:
break;
}
}
set_controller_type(GPCT_NOCONTROLLER);
CloseDevice(game_io_msg);
DeleteStdIO(game_io_msg);
DeletePort(game_msg_port);
printf("\nExiting program... 2 minutes with no activity sensed\n1> ");
return;
}
/* if mouse didnt move far enough to trigger a report, then caller
* will also report that 30 seconds (1800 vblanks) has elapsed
*/
int maybe_mouse_moved()
{
SHORT xmove, ymove;
xmove = game_data->ie_X;
ymove = game_data->ie_Y;
if(xmove != 0 || ymove != 0)
{
printf("\nMouse Moved by X-value %ld, Y-value %ld",
xmove, ymove);
timeouts = 0;
}
if(xmove < 0) xmove = -xmove;
if(ymove < 0) ymove = -ymove;
return(MAX(xmove,ymove));
}
int set_controller_type(type)
SHORT type;
{
game_io_msg->io_Command = GPD_SETCTYPE;
/* set type of controller to mouse */
*gamedata = type;
/* this means dont generate any more reports */
SendIO(game_io_msg);
/* set it up */
/* this command doesn't wait... returns immediately */
WaitPort(game_msg_port);
GetMsg(game_msg_port);
return(0);
}